package com.chen.config;

import com.chen.util.PathUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * @Author:chenao
 * @DATE:2022/3/12 17:40
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String uploadPath = PathUtils.getUploadPath();
        //格式为"file:C:/Users/app-fitness/app-admin/target/upload/"
        String location="file:"+uploadPath;
        String property = System.getProperties().getProperty("os.name");
        if (property.contains("Windows")) {
            //Windows下
            registry.addResourceHandler("/img/**").addResourceLocations(location);
        } else{
            //Linux系统
            registry.addResourceHandler("/img/**").addResourceLocations(location);
        }
        super.addResourceHandlers(registry);
    }
}
